package com.hz.ys_financial.dao;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.hz.framework.MyInterFace.SystemInterFace;
import com.hz.framework.dao.CommonDBDao;
import com.hz.framework.dao.CommonDao;
import com.hz.framework.util.DateUtil;
import com.hz.framework.util.SqlParameter;
import com.hz.ys_financial.bean.Takingsorpay;
import com.hz.ys_financial.dbsql.FinancialSql;
import com.hz.ys_stock.dbsql.StockSql;
import com.hz.ys_system.dao.QueryDao;

/**
 * *****************************************************************************
 *               Copyright(c) 2010 by 哈尔滨华泽数码科技有限公司.
 *                       All rights reserved.
 *******************************************************************************
 *     File Name         :  com.hz.ys_stock.dao.SupplierDao.java
 *     Description(说明)	:  其他收入支出信息
 * -----------------------------------------------------------------------------
 *     No.        Date              Revised by           Description	  
 *     1		Jun 8, 2011				韩飞	              Created
 *****************************************************************************
 */
public class OtherPayDao implements SystemInterFace{
	
	/**
	 * @author 韩飞
	 * @time Nov 25, 2011	
	 * @param request 
	 * @param tpflag   tak 收入 或 pay 支出
	 * @return 
	 * 方法功能: 查询其他收入支出信息
	 */
	public String SelOtherPay(HttpServletRequest request){
		StringBuilder sbSQL = new StringBuilder();
		sbSQL.append(FinancialSql.SEL_OTHERPAY_LIST);
		
		sbSQL.append(new QueryDao().QueryInfo(request , new SqlParameter("suppliername","tpperson") , "=") );
		//时间条件查询
		sbSQL.append(new QueryDao().QueryDateInfo(request,"tpdate","begin","end",true));
		
		sbSQL.append(" order by tpdate desc ");
		
		return sbSQL.toString();
	}
	
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @return 
	 * 方法功能:查询所有人员
	 */
	public List SelPerson(){
		CommonDBDao dbo= new CommonDBDao();
		return dbo.DBjsonList(StockSql.SEL_BUYER);
	}
	/**
	 * @author 韩飞
	 * @time Nov 17, 2011	
	 * @param puser
	 * @return
	 * @throws Exception 
	 * 方法功能: 保存其他收入支出信息
	 */
	public boolean DoSaveOtherPay( Takingsorpay to ) throws Exception {
		boolean ins = false;
		CommonDao dbd= new CommonDao();
		if(to!=null){
			//保存或更新 下拉选名称表
			to.setCreatetime(DateUtil.getDateTime());
			to.setFinalflag("已结算");
			ins = dbd.insertinfor(to);
		}
		return ins;
	}
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @param request
	 * @return 
	 * 方法功能: 删除 其他收入支出信息
	 */
	public boolean Del_OtherPay(HttpServletRequest request){
		String tpid = CommonDao.isnull(request.getParameter("tpid"));
		CommonDBDao dbo= new CommonDBDao();
		return dbo.executeSQL(FinancialSql.DEL_PAYMONEY, new SqlParameter(tpid));
	}
	
	
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @param request
	 * @return 
	 * 方法功能: 根据 sid 查询 对应的采购付款信息
	 */
	public void SelOtherPayInfo(HttpServletRequest request) throws Exception {
		String tpid = CommonDao.isnull(request.getParameter("tpid"));
		CommonDao dbd= new CommonDao();
		Map map = (Map)dbd.queryObjectByPS(FinancialSql.SEL_PAYMONEY_INFO, new SqlParameter(tpid),null);
		request.setAttribute("updinfo", map);
	}
	/**
	 * @author 韩飞
	 * @time Nov 16, 2011	
	 * @return 
	 * 方法功能: 修改其他收入支出信息
	 */
	public boolean UpdOtherPay( Takingsorpay to ){
		boolean ins = false;
		CommonDao dbo= new CommonDao();
		if(to!=null){
			//保存或更新 
			to.setCreatetime(DateUtil.getDateTime());
			to.setFinalflag("已结算");
			ins = dbo.updateinfor(to);
		}
		return ins;
	}
	
}
